﻿using DevExpress.ExpressApp.Blazor.Editors;
using DevExpress.ExpressApp.Blazor.Editors.Adapters;
using DevExpress.ExpressApp.Model;
using EasyXaf.EntityDesigner.Editors.LookupStringPropertyEditor;

namespace EasyXaf.EntityDesigner.Editors.LookupStringPropertyEditors;

public class LookupStringPropertyEditor : BlazorPropertyEditorBase
{
    public LookupStringPropertyEditor(Type objectType, IModelMemberViewItem model)
        : base(objectType, model)
    {
    }

    protected override IComponentAdapter CreateComponentAdapter()
    {
        IEnumerable<string> items = [];
        if (CurrentObject is IListBoxItemsProvider listBoxItemsProvider)
        {
            items = listBoxItemsProvider.GetListBoxItems(PropertyName);
        }

        return new LookupStringPropertyEditorAdapter(new LookupStringPropertyEditorModel
        {
            Items = items,
        });
    }
}
